// 主界面
;define(function(require, exports, module) {
    'use strict';
    var util = require("util");
    var base = require(CONFIG.BasePath + "js/enterprise/base");
    var router = require("../hash/pageRouter");
    var css_apply_success = require("./apply_success.css");
    var financeId;
    var userID;
    var databind = require("databind");
    var dialog = require("dialog");
    var productType;

    var init = function(page){
    	financeId = page.params.financeId;
    	userID = page.params.userID;
    	
    	if (productType == 4) {
			$("#progress").attr("src", "../../../res/png/progress_apply31.png");
		}
    	
    	if (userID == null && (base.getData("sid") == null || base.getData("sid") == "" || base.getData("sid") == undefined)) {
			location.href = "../login/login.html";
		}
    	
    	layer.confirm('是否直接提交融资申请，提交后将无法再次修改。', {
		  btn: ['确定','取消'] //按钮
		}, function(){
		  submitFinanceApplication(financeId);
		}, function(){
		});
    	
    	router.init();
		initEvent();
    };
    
	var initEvent = function(){
		databind.fillInput($("#apply_success"), {action: "inquireFinanceApplicationDetail.json?financeId=" + financeId, nocode: true});
		
		$("#apply_success .submit").unbind("click").click(function(){
			dialog.showConfirmDialog("提交融资", "提交后将无法再次修改，是否确认提交?", function(){
				submitFinanceApplication(financeId);
			});
		});
	};
	
	//确认提交融资申请
    var submitFinanceApplication = function(financeId){
		base.fnAjax({
			action: "submitFinanceApplication.json",
			async: false,
			nocode: true,
			oData: {
                financeId: financeId
            }, //传递参数
            fnSuccess: function(data) {
                if (data.status == 200) {
                	base.alert(1, "提交成功！");
                	location.href = "../account/account.html";
                } else {
                	base.alert(2, data.message);
                }
            }
		});
	};

    return {
        init:init
    };
});